package com.jia.sms.configuration;

import com.jia.sms.interceptor.LoginRedisInterceptor;
import com.jia.sms.interceptor.RefreshTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author jia
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Resource
    public StringRedisTemplate stringRedisTemplate;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // session 拦截
//        registry.addInterceptor(new LoginSessionInterceptor())
//                .excludePathPatterns(
//                        "/user/login",
//                        "/user/code"
//                );
        // 0 优先级 大于 1
        registry.addInterceptor(new LoginRedisInterceptor())
                .excludePathPatterns(
                        "/user/login",
                        "/user/code"
                ).order(1);
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);
    }
}
